<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class SyntaxSuggest::AroundBlockScan - syntax_suggest: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-code_block">#code_block</a>
    <li ><a href="#method-i-force_add_empty">#force_add_empty</a>
    <li ><a href="#method-i-force_add_hidden">#force_add_hidden</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-lines">#lines</a>
    <li ><a href="#method-i-lookahead_balance_one_line">#lookahead_balance_one_line</a>
    <li ><a href="#method-i-scan_adjacent_indent">#scan_adjacent_indent</a>
    <li ><a href="#method-i-scan_neighbors_not_empty">#scan_neighbors_not_empty</a>
    <li ><a href="#method-i-scan_while">#scan_while</a>
    <li ><a href="#method-i-stop_after_kw">#stop_after_kw</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-SyntaxSuggest::AroundBlockScan">
    <h1 id="class-SyntaxSuggest::AroundBlockScan" class="class">
      class SyntaxSuggest::AroundBlockScan
    </h1>

    <section class="description">
    
<p>This class is useful for exploring contents before and after a block</p>

<p>It searches above and below the passed in block to match for whatever criteria you give it:</p>

<p>Example:</p>

<pre>def dog         # 1
  puts &quot;bark&quot;   # 2
  puts &quot;bark&quot;   # 3
end             # 4

scan = AroundBlockScan.new(
  code_lines: code_lines
  block: CodeBlock.new(lines: code_lines[1])
)

scan.scan_while { true }

puts scan.before_index # =&gt; 0
puts scan.after_index  # =&gt; 3</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(code_lines:, block:)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 30</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-value">code_lines:</span>, <span class="ruby-value">block:</span>)
  <span class="ruby-ivar">@code_lines</span> = <span class="ruby-identifier">code_lines</span>
  <span class="ruby-ivar">@orig_indent</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">current_indent</span>

  <span class="ruby-ivar">@stop_after_kw</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@force_add_empty</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@force_add_hidden</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@target_indent</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-ivar">@scanner</span> = <span class="ruby-constant">ScanHistory</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">code_lines:</span> <span class="ruby-identifier">code_lines</span>, <span class="ruby-value">block:</span> <span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-code_block" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">code_block</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return the currently matched lines as a ‘CodeBlock`</p>

<p>When a ‘CodeBlock` is created it will gather metadata about itself, so this is not a free conversion. Avoid allocating more CodeBlock’s than needed</p>

                              <div class="method-source-code" id="code_block-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 217</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">code_block</span>
  <span class="ruby-constant">CodeBlock</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">lines:</span> <span class="ruby-identifier">lines</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-force_add_empty" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">force_add_empty</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>When using this flag, ‘scan_while` will bypass the block it’s given and always add a line that responds truthy to ‘CodeLine#empty?`</p>

<p>Empty lines contain no code, only whitespace such as leading spaces a newline.</p>

                              <div class="method-source-code" id="force_add_empty-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">force_add_empty</span>
  <span class="ruby-ivar">@force_add_empty</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-force_add_hidden" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">force_add_hidden</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>When using this flag, ‘scan_while` will bypass the block it’s given and always add a line that responds truthy to ‘CodeLine#hidden?`</p>

<p>Lines are hidden when they’ve been evaluated by the parser as part of a block and found to contain valid code.</p>

                              <div class="method-source-code" id="force_add_hidden-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 49</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">force_add_hidden</span>
  <span class="ruby-ivar">@force_add_hidden</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Managable rspec errors</p>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 228</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-node">&quot;#&lt;#{self.class}:0x0000123843lol &gt;&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lines" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lines</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the lines matched by the current scan as an array of CodeLines</p>

                              <div class="method-source-code" id="lines-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 223</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lines</span>
  <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">lines</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lookahead_balance_one_line" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lookahead_balance_one_line</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scanning is intentionally conservative because we have no way of rolling back an agressive block (at this time)</p>

<p>If a block was stopped for some trivial reason, (like an empty line) but the next line would have caused it to be balanced then we can check that condition and grab just one more line either up or down.</p>

<p>For example, below if we’re scanning up, line 2 might cause the scanning to stop. This is because empty lines might denote logical breaks where the user intended to chunk code which is a good place to stop and check validity. Unfortunately it also means we might have a “dangling” keyword or end.</p>

<pre>1 def bark
2
3 end</pre>

<p>If lines 2 and 3 are in the block, then when this method is run it would see it is unbalanced, but that acquiring line 1 would make it balanced, so that’s what it does.</p>

                              <div class="method-source-code" id="lookahead_balance_one_line-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 141</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lookahead_balance_one_line</span>
  <span class="ruby-identifier">kw_count</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">end_count</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">lines</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">kw_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">is_kw?</span>
    <span class="ruby-identifier">end_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">is_end?</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">kw_count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">end_count</span> <span class="ruby-comment"># nothing to balance</span>

  <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">commit_if_changed</span> <span class="ruby-comment"># Rollback point if we don&#39;t find anything to optimize</span>

  <span class="ruby-comment"># Try to eat up empty lines</span>
  <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">scan</span>(
    <span class="ruby-value">up:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-identifier">line</span>.<span class="ruby-identifier">hidden?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span> },
    <span class="ruby-value">down:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-identifier">line</span>.<span class="ruby-identifier">hidden?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span> }
  )

  <span class="ruby-comment"># More ends than keywords, check if we can balance expanding up</span>
  <span class="ruby-identifier">next_up</span> = <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">next_up</span>
  <span class="ruby-identifier">next_down</span> = <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">next_down</span>
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">end_count</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">kw_count</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">next_up</span>&amp;.<span class="ruby-identifier">is_kw?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">next_up</span>.<span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@target_indent</span>
      <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">scan</span>(
        <span class="ruby-value">up:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-identifier">line</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">next_up</span> },
        <span class="ruby-value">down:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-keyword">false</span> }
      )
      <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">commit_if_changed</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">-1</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">next_down</span>&amp;.<span class="ruby-identifier">is_end?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">next_down</span>.<span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@target_indent</span>
      <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">scan</span>(
        <span class="ruby-value">up:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-keyword">false</span> },
        <span class="ruby-value">down:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span>) { <span class="ruby-identifier">line</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">next_down</span> }
      )
      <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">commit_if_changed</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-comment"># Rollback any uncommitted changes</span>
  <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">stash_changes</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan_adjacent_indent" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">scan_adjacent_indent</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Scan blocks based on indentation of next line above/below block</p>

<p>Determines indentaion of the next line above/below the current block.</p>

<p>Normally this is called when a block has expanded to capture all “neighbors” at the same (or greater) indentation and needs to expand out. For example the ‘def/end` lines surrounding a method.</p>

                              <div class="method-source-code" id="scan_adjacent_indent-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 200</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">scan_adjacent_indent</span>
  <span class="ruby-identifier">before_after_indent</span> = []

  <span class="ruby-identifier">before_after_indent</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">next_up</span>&amp;.<span class="ruby-identifier">indent</span> <span class="ruby-operator">||</span> <span class="ruby-value">0</span>)
  <span class="ruby-identifier">before_after_indent</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">next_down</span>&amp;.<span class="ruby-identifier">indent</span> <span class="ruby-operator">||</span> <span class="ruby-value">0</span>)

  <span class="ruby-ivar">@target_indent</span> = <span class="ruby-identifier">before_after_indent</span>.<span class="ruby-identifier">min</span>
  <span class="ruby-identifier">scan_while</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">not_empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@target_indent</span> }

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan_neighbors_not_empty" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">scan_neighbors_not_empty</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Finds code lines at the same or greater indentation and adds them to the block</p>

                              <div class="method-source-code" id="scan_neighbors_not_empty-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 188</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">scan_neighbors_not_empty</span>
  <span class="ruby-ivar">@target_indent</span> = <span class="ruby-ivar">@orig_indent</span>
  <span class="ruby-identifier">scan_while</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">not_empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-ivar">@target_indent</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan_while" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">scan_while</span><span
                                class="method-args">() { |line| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Main work method</p>

<p>The <a href="AroundBlockScan.html#method-i-scan_while"><code>scan_while</code></a> method takes a block that yields lines above and below the block. If the yield returns true, the @before_index or @after_index are modified to include the matched line.</p>

<p>In addition to yielding individual lines, the internals of this object give a mini DSL to handle common situations such as stopping if we’ve found a keyword/end mis-match in one direction or the other.</p>

                              <div class="method-source-code" id="scan_while-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 88</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">scan_while</span>
  <span class="ruby-identifier">stop_next_up</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">stop_next_down</span> = <span class="ruby-keyword">false</span>

  <span class="ruby-ivar">@scanner</span>.<span class="ruby-identifier">scan</span>(
    <span class="ruby-value">up:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">kw_count</span>, <span class="ruby-identifier">end_count</span>) {
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">stop_next_up</span>
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@force_add_hidden</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">hidden?</span>
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@force_add_empty</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span>

      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@stop_after_kw</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">kw_count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">end_count</span>
        <span class="ruby-identifier">stop_next_up</span> = <span class="ruby-keyword">true</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">line</span>
    },
    <span class="ruby-value">down:</span> <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">kw_count</span>, <span class="ruby-identifier">end_count</span>) {
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">stop_next_down</span>
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@force_add_hidden</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">hidden?</span>
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@force_add_empty</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span>

      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@stop_after_kw</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">end_count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">kw_count</span>
        <span class="ruby-identifier">stop_next_down</span> = <span class="ruby-keyword">true</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">line</span>
    }
  )

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-stop_after_kw" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">stop_after_kw</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Tells ‘scan_while` to look for mismatched keyword/end-s</p>

<p>When scanning up, if we see more keywords then end-s it will stop. This might happen when scanning outside of a method body. the first scan line up would be a keyword and this setting would trigger a stop.</p>

<p>When scanning down, stop if there are more end-s than keywords.</p>

                              <div class="method-source-code" id="stop_after_kw-source">
            <pre><span class="ruby-comment"># File syntax_suggest/around_block_scan.rb, line 73</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stop_after_kw</span>
  <span class="ruby-ivar">@stop_after_kw</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

